//
//  FriendSelectSegView.m
//  project
//
//  Created by 黄建华 on 2018/8/9.
//  Copyright © 2018年 黄建华. All rights reserved.
//

#import "FriendSelectSegView.h"
#import "UIButton+Badge.h"
@implementation FriendSelectSegView {
    UIView *line;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        NSArray *infoArray = [NSArray arrayWithObjects:SN_Text(@"系统信息"), SN_Text(@"好友请求"), SN_Text(@"我的亲友"), nil];
        for (int i = 0; i < 3; i++) {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = SNFRAME(self.width / 3 *i, 0, self.width / 3, self.height);
            [button addTarget:self
                       action:@selector(buttonclick:)
             forControlEvents:UIControlEventTouchUpInside];
            button.tag             = i + 101;
            button.titleLabel.font = [UIFont systemFontOfSize:15];
            if (i == 0) {
                [button setTitleColor:SNCOLORBLACK forState:UIControlStateNormal];
            } else {
                [button setTitleColor:SNCOLORGRAY forState:UIControlStateNormal];
            }
            button.titleLabel.adjustsFontSizeToFitWidth = YES;
            button.titleLabel.minimumScaleFactor = 0.5;
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
            [button setTitle:[infoArray objectAtIndex:i] forState:UIControlStateNormal];
            [self addSubview:button];
        }
        line                 = [[UIView alloc]init];
        line.frame           = CGRectMake(0, self.height-2, (HHHWIDTH)/3, 2);
        line.backgroundColor = SNCOLORBLACK;
        [self addSubview:line];
    }
    return self;
}

// 系统信息设置
- (void)showBadGe:(NSInteger)type {
    for (UIButton *button in self.subviews) {
        if ([button isKindOfClass:[UIButton class]]) {
            if (button.tag == type +100) {
            } else {
            }
        }
    }
}

- (void)buttonclick:(UIButton *)sender {
    for (UIButton *button in self.subviews) {
        if ([button isKindOfClass:[UIButton class]]) {
            if (button.tag == sender.tag) {
                [button setTitleColor:SNCOLORBLACK forState:UIControlStateNormal];
            } else {
                [button setTitleColor:SNCOLORGRAY forState:UIControlStateNormal];
            }
        }
    }
    
    NSInteger type = 1;
    if (sender.tag - 100 == 1) {
        type = 1;
    }
    if (sender.tag - 100 == 2) {
        type = 2;
    }
    if (sender.tag - 100 == 3) {
        type = 3;
    }
    line.frame = CGRectMake((type-1) *(HHHWIDTH)/3, self.height-2, HHHWIDTH/3, 2);
    if (_selectType) {
        _selectType(type);
    }
}

@end
